package geektime.spring.springbucks.waiterservice;

import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module;
import geektime.spring.springbucks.waiterservice.controller.PerformanceInteceptor;
import java.util.TimeZone;
import javafx.util.Builder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@EnableCaching
@EnableJpaRepositories
public class WaiterServiceApplication implements WebMvcConfigurer {

  public static void main(String[] args) {
    SpringApplication.run(WaiterServiceApplication.class, args);
  }

  @Bean
  public Hibernate5Module hibernate5Module() {
    return new Hibernate5Module();
  }


  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(new PerformanceInteceptor()).addPathPatterns("/coffee/**")
        .addPathPatterns("/order/**");
  }

  public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer(){
    return builder->{
      builder.indentOutput(true);
      builder.timeZone(TimeZone.getTimeZone("Asia/Shanghai"));
    };
  }
}
